package etnorservice.etnor_service.service.impl;

import etnorservice.etnor_service.domain.po.*;
import etnorservice.etnor_service.domain.vo.DeveloperVO;
import etnorservice.etnor_service.mapper.UserMapper;
import etnorservice.etnor_service.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2024/08/22/15:08
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<User> findUserByAccountAndPassword(User user) {
        return userMapper.findUserByAccountAndPassword(user);
    }

    @Override
    public User findRoleByAccount(Integer account) {
        return userMapper.findRoleByAccount(account);
    }

    @Override
    public List<DeveloperVO> findDevelopers() {
        List<Developer> developers= userMapper.findAllDevelopers();
        List<DeveloperVO> developerVOS=new ArrayList<>();
        for(Developer developer:developers){
            DeveloperVO developerVO = new DeveloperVO();
            developerVO.setIsgooddeveloper(developer.getIsgooddeveloper());
            developerVO.setIcon(developer.getIcon());
            developerVO.setId(developer.getId());
            developerVO.setName(developer.getName());
            developerVO.setSubmit(developer.getSubmit());
            developerVO.setIsVip(developer.getIsVip());
            developerVO.setIsuseful(developer.getIsuseful());
            developerVO.setEmail(developer.getEmail());
            developerVO.setWebsite(developer.getWebsite());
            developerVOS.add(developerVO);
        }
        return developerVOS;
    }

    @Override
    public DeveloperVO findDeveloperById(Integer id) {
        return userMapper.findDeveloperById(id);
    }

    @Override
    public UserDetails findUserDetail(String account) {
        return userMapper.findUserDetailsByAccount(account);
    }

    @Override
    public List<MenuItem> findUserPermissions(Integer userId) {
        return userMapper.findUserPermissions(userId);
    }

    @Override
    public Integer getSumDeveloper() {
        //这里查所有用户，后期替换
        return userMapper.findAllUsers();
    }

    @Override
    public void registerUser(LoginAndRegister register) {
         userMapper.registerUser(register);
    }

    @Override
    public List<User> findRoleByEmail(String email) {
        return userMapper.findUserByEmail(email);
    }
}
